Skip to content

修复终端模式下发不出空格和退格 - #233

Merged
chenxuuu merged 1 commit into
chenxuuu:masterfrom
LuaRobot:fix/terminal-space-backspace
Nov 6, 2026
Merged

chenxuuu merged 1 commit into
chenxuuu:masterfrom
LuaRobot:fix/terminal-space-backspace

Conversation

@LuaRobot

@LuaRobot LuaRobot commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Fixes #176
Fixes #217

终端模式的按键只有一个来源,挂在 Frame 上的 PreviewTextInput,但有两类键根本走不到这里:

  • 空格:中文输入法把它当候选上屏键吃掉了,不会产生 TextComposition
  • 退格:Key.Back 本身就不产生 TextComposition

所以在 PreviewKeyDown 里补上这两个键,直接发 0x20 / 0x08,并把 e.Handled 置 true,避免输入法模式下重复发送。

另外把 Encoding.ASCII 换成设置里的串口编码(Tools.Global.GetEncoding()):原先全角空格、中文都会被 ASCII 编码替换成 ?,看起来也像「空格没了」。

说明:我这台机器是 Linux,仓库是 WPF + TargetFrameworkVersion=v4.6.2 的老式 csproj,本地编不了,改动是读代码 + 对照 WPF 的输入事件链改的,麻烦你在 Windows 上跑一下确认手感(尤其输入法开着时连续敲空格/退格)。

- 空格是中文输入法的上屏键、退格不产生 TextComposition,两者都不会触发
  PreviewTextInput,之前完全发不出去;改在 PreviewKeyDown 里显式发送 0x20/0x08
- 终端输入原先写死 Encoding.ASCII,全角空格和中文都会被替换成 '?',
  改为使用设置里的串口编码

Fixes chenxuuu#176
Fixes chenxuuu#217
@chenxuuu

chenxuuu commented Nov 6, 2026

Copy link
Copy Markdown
Owner

LGTM

@chenxuuu
chenxuuu merged commit e1786c1 into chenxuuu:master Nov 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

终端方式输入,空格识别不到 终端模式无法输入空格和退格键,旧版本是可以的

2 participants